<template>
	<view class="u-page">
		<view class="content">
			<view class="success"><image src="../../../static/icon/phoneyunyin.png" mode=""></image></view>
			<view class="title">运营商手机号验证</view>
			<view class="formdata">
				<view class="listLable">
					<view class="label">姓名</view>
					<view class="name" >{{formData.username}}</view>
					
				</view>
				<view class="listLable">
					<view class="label">手机号码</view><view class="name"><uni-easyinput v-model="formData.authenticationPhone" :value="formData.authenticationPhone" @input="phone" placeholder="请输入内容" type="number"></uni-easyinput>
</view>
				</view>
		
				<view class="sbut">
					<button type="warn" @click="authentication()" >验证</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				formData:{
					"authenticationPhone":'',
					"username":'',
					"idCard":'',
					"phoneLssue":'',
					"phoneAttestation":'0'
				},
				
			}
		},
		onLoad() {
			this.users();
		},
		
		methods: {
			//获取用户认证信息
			async users(){
				const user = await this.GQL({
						"operationName": "allSlUsers",
						"query": "query allSlUsers($filter: SlUserFilter) { allSlUsers(filter:$filter) { nodes { uid username phone phoneAttestation idCard authenticationPhone} } }",
						"variables": {"filter": {"uid":{"equalTo":uni.getStorageSync('userData').uid}}}
				})
				this.formData = user.data.allSlUsers.nodes[0]
				
			},
			phone(e){
				this.formData.authenticationPhone = e
			},
			username(e){
				this.formData.username = e
			},
			//下一步
			authentication(){
				let that = this
				// console.log('11111',this.formData)
				
				//验证手机号实名
				uni.request({
					url:that.HttpServe+"/Api/phoneAuth",
					method:"post",
					data:{
						realname:that.formData.username,
						idcard:that.formData.idCard,
						phone:that.formData.authenticationPhone,
					},
					success(res) {
						console.log('11111',res)
						if(res.data.code == 200){
							// that.usersdata()
							// if()
							let da = res.data
							console.log('2222',da.data.province);
							if(da.data.res =='1'){
								//验证成功
								that.formData.phoneLssue = da.data.province+'-'+da.data.city+'-'+da.data.type
								that.userinfo()
							}else{
								//验证失败
								if(da.data.rescode =='21'){
									// uni.showToast({ title: '验证失败，姓名不匹配', icon: 'error', duration: 3000 });
									uni.showModal({
										title: '提示',
										content: '验证失败，姓名不匹配',
										success: function (res) {
											uni.hideLoading();
											
										}
									});
								}else if(da.data.rescode == '22'){
									// uni.showToast({ title: '验证失败，身份证不匹配', icon: 'error', duration: 3000 });
									uni.showModal({
										title: '提示',
										content: '验证失败，身份证不匹配',
										success: function (res) {
											uni.hideLoading();
											
										}
									});
								}else{
									// uni.showToast({ title: '验证失败，姓名身份证均不匹配', icon: 'error', duration: 3000 });
									uni.showModal({
										title: '提示',
										content: '验证失败，姓名身份证均不匹配',
										success: function (res) {
											uni.hideLoading();
											
										}
									});
								}
								
							}
						}else{
							uni.showToast({ title: '验证失败', icon: 'error', duration: 3000 });
						}
					}
				})
			},
			async userinfo(){
				this.formData.phoneAttestation = '1'
				// this.formData.authenticationPhone = 
				const user = await this.GQL({
						"operationName": "updateSlUserByUid",
						"query": "mutation updateSlUserByUid($input: UpdateSlUserByUidInput!) { updateSlUserByUid(input: $input) { slUser { uid phoneAttestation } } }",
						"variables": {"input": {"uid":uni.getStorageSync('userData').uid,"slUserPatch":this.formData}}
				})
				if(user.data.updateSlUserByUid.slUser !=''){
					uni.showModal({
						title: '提示',
						content: '认证成功',
						success: function (res) {
							if (res.confirm) {
								uni.navigateBack({
									delta:4
								})
							} else if (res.cancel) {
								uni.navigateBack({
									delta:4
								})
							}
						}
					});
				}
			}
			
			
		}
	}
</script>

<style lang="scss">
	.content{
		// margin: 15px;
		background-color: #FFFFFF;
		text-align: center;
	}
	.success{
		padding-top: 30px;
		image{
			width: 60px;
			height: 60px;
		}
	}
	.title{
		margin: 20px 0px;
		font-size: 18px;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #161E3E;
		line-height: 16px;
	}
	
	.formdata{
		
		.listLable{
			display: flex;
			height: 30px;
			margin: 5px 0px;
			font-size: 15px;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #161E3E;
			line-height: 16px;
		}
		.label{
			width: 100px;
			line-height: 30px;
		}
		.name{
			font-size: 15px;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #767B8D;
			line-height: 26px;
		}
	}
	.sbut{
		padding-top: 20px;
	}
</style>
